function firstUniqChar(s: string): number {
  let map = new Map();
  for (let i = 0; i < s.length; i++) {
    if (map.has(s[i])) {
      map.set(s[i], -1);
    } else {
      map.set(s[i], i);
    }
  }
  let n = s.length;
  for (let item of map.values()) {
    if (item != -1 && item < n) {
      n = item;
    }
  }
  if (n === s.length) {
    n = -1;
  }
  return n;
}
console.log(firstUniqChar("leetcode"));
